﻿using DrawSimple1.ViewModels;
using System.Windows;
using System.Windows.Controls;

namespace DrawSimple1
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.DataContext = new MianWindowlModelView();  // 数据源

            listView.Items.Add(new { ID = 1, Name = "Dakota Rice", Salary = 36738.ToString("C"), Country = "Niger" });
            listView.Items.Add(new { ID = 2, Name = "Dakota Rice", Salary = 36738.ToString("C"), Country = "Niger" });
            listView.Items.Add(new { ID = 3, Name = "Dakota Rice", Salary = 36738.ToString("C"), Country = "Niger" });
            listView.Items.Add(new { ID = 4, Name = "Dakota Rice", Salary = 36738.ToString("C"), Country = "Niger" });
        }

        private void listView_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            var gv = listView.View as GridView;
            if (gv != null)
            {
                int _count = gv.Columns.Count;
                int _width = (int)listView.ActualWidth - (int)(listView.ActualWidth * 0.009);
                foreach (var item in gv.Columns)
                {
                    item.Width = _width / _count;
                }
            }
        }

        private void listBox_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            //foreach (var item in listBox.Items)
            //{
            //    if (item is ListBoxItem listboxitem)
            //    {
            //        double width = listboxitem.ActualWidth;
            //        double lastChildBeforeWidth = 0;
            //        if (listboxitem.Content is StackPanel stackPanel)
            //        {
            //            stackPanel.Width = width;
            //            foreach (var chidren in stackPanel.Children)
            //            {
            //                if (chidren is CheckBox checkBox)
            //                {
            //                    lastChildBeforeWidth += checkBox.ActualWidth;
            //                }
            //                else if (chidren is TextBlock textBlock)
            //                {
            //                    lastChildBeforeWidth += textBlock.ActualWidth;
            //                }
            //                else if (chidren is Canvas canvas)
            //                {
            //                    canvas.Width = width - lastChildBeforeWidth;
            //                    //foreach (var canvasChildren in canvas.Children)
            //                    //{
            //                    //    var offset = canvas.Width - 50;
            //                    //    if (canvasChildren is TextBlock textBlock1)
            //                    //    {
            //                    //        Canvas.SetRight(textBlock1, offset);
            //                    //        offset -= 5;
            //                    //    }
            //                    //}
            //                }
            //            }
            //        }
            //    }
            //}
        }
    }
}